package com.ant.rxjava.mvp;

import android.databinding.DataBindingUtil;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextPaint;

import com.ant.rxjava.mvp.databinding.AcMainLayoutBinding;

public class MainActivity extends AppCompatActivity implements MainViewInter {

    private AcMainLayoutBinding binding;
    private MainPresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.ac_main_layout);
        binding = DataBindingUtil.setContentView(this, R.layout.ac_main_layout);
        presenter = new MainPresenter();
        presenter.attachView(this);

        binding.acMainImg.setImageBitmap(getBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.advertise_picture)));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.detachView();
    }

    /***************************************************************************************/

    @Override
    public void showLoading(boolean toShow) {

    }

    @Override
    public void showData(String data) {

    }

    @Override
    public void showFailureMess(String mess) {

    }

    @Override
    public void showErrorMess(String mess) {

    }

    public Bitmap getBitmap(Bitmap bitmap) {
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canv = new Canvas(output);
        canv.drawARGB(0, 0, 0, 0);
        TextPaint paint = new TextPaint();
        paint.setAntiAlias(true);
        paint.setColor(Color.GRAY);
        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        RectF rectf = new RectF(rect);
        canv.drawRoundRect(rectf, 100, 100, paint);
        paint.setXfermode(new
                PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canv.drawBitmap(bitmap, rect, rect, paint);

        return output;
    }
}
